package com.tonypy.mqtt.mqttdemo.mqtt;


import com.tonypy.mqtt.mqttdemo.constants.ProfileConstant;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Profile;
import org.springframework.integration.mqtt.support.MqttHeaders;
import org.springframework.messaging.Message;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 获取消息
 *
 * @author tonypy
 */
@Component
@Slf4j
@Profile(ProfileConstant.BOX)
public class MqttReceive {
    /**
     * strategyIp 返回消息的策略服务器的ip
     * message  返回的消息
     */
    @Async
    void handler(String strategyIp, Message<?> message) {
        String msg = message.getPayload().toString();
        String topic = (String) message.getHeaders().get(MqttHeaders.RECEIVED_TOPIC);
        log.info("-----------收到策略服务器消息------"+topic+":\n"+msg);
    }

}
